<template>
	<view class="p15 resume">
		<uni-section title="培训经历" type="line"></uni-section>
		<uni-forms class="form" ref="form" :modelValue="form" label-position="left" label-width="80px">
			<uni-forms-item label="培训课程" required>
				<uni-easyinput v-model="form.ctrainlesson" placeholder="请输入培训课程" />
			</uni-forms-item>
			<uni-forms-item label="开始日期" required>
				<uni-datetime-picker type="date" placeholder="请输入开始日期" :clear-icon="false" v-model="form.timefrom"/>
			</uni-forms-item>
			<uni-forms-item label="结束日期" required>
				<uni-datetime-picker type="date" placeholder="请输入结束日期" :clear-icon="false" v-model="form.timeto"/>
			</uni-forms-item>
			<uni-forms-item label="培训机构" required>
				<uni-easyinput v-model="form.ctrainname" placeholder="请输入培训机构" />
			</uni-forms-item>
			<uni-forms-item label="描述" required>
				<uni-easyinput v-model="form.cdescribe" placeholder="请输入描述" type="textarea" />
			</uni-forms-item>
			<uni-forms-item label="培训地点" required>
				<uni-easyinput v-model="form.ctrainplace" placeholder="请输入培训地点" type="textarea" />
			</uni-forms-item>
		</uni-forms>
		<button class="default-button" @click="save()">提交</button>
	</view>
</template>

<script>
	export default {
		name:"resume_train",
		data() {
			return {
				id:0,
				resume_id:0,
				form:{}
			};
		},
		onLoad(options){
			this.id = options.id
			this.resume_id = options.resume_id
			this.onGetData()
		},
		methods: {
			onGetData(){
				let _this = this
				this.$request('/api/get_one_skill_train','POST',{resume_id:_this.resume_id,id:_this.id}).then(res => {
					_this.form = res.data ? res.data : {}
				}).catch(err => {
					console.log(err)
				})
			},
			save(){
				if(!this.form.ctrainlesson){
					uni.showToast({title: '请输入培训课程',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.timefrom){
					uni.showToast({title: '请输入开始日期',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.timeto){
					uni.showToast({title: '请输入结束日期',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.ctrainname){
					uni.showToast({title: '请输入培训机构',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.ctrainplace){
					uni.showToast({title: '请输入培训地点',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.cdescribe){
					uni.showToast({title: '请输入描述',icon: 'error',duration: 2000})
					return;
				}
				
				let _this = this
				this.form.resume_id = this.resume_id
				this.$request('/api/addTrain','POST',this.form).then(res => {
					if(res.code != 0){
						uni.showToast({title: '保存失败',icon: 'error',duration: 2000})
						return;
					}
					uni.showToast({title: '保存成功',icon: 'success',duration: 2000})
					uni.navigateTo({
						url: "/user/resume/resume"
					});
				}).catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style>

</style>